package com.library.service.impl;


import com.library.common.core.text.Convert;
import com.library.common.utils.StringUtils;
import com.library.domain.BoBookType;
import com.library.mapper.BoBookTypeMapper;
import com.library.service.IBoBookTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.library.service.impl.BoBookServiceImpl.BOOK_NO_NOT_UNIQUE;
import static com.library.service.impl.BoBookServiceImpl.BOOK_NO_UNIQUE;

/**
 * 图书类型管理 服务层实现
 *
 * @author wanghongjie
 * @date 2020-01-18
 */
@Service
public class BoBookTypeServiceImpl implements IBoBookTypeService {
    @Autowired
    private BoBookTypeMapper boBookTypeMapper;

    /**
     * 查询图书类型管理信息
     *
     * @param id 图书类型管理ID
     * @return 图书类型管理信息
     */
    @Override
    public BoBookType selectBoBookTypeById(Long id) {
        return boBookTypeMapper.selectBoBookTypeById(id);
    }

    @Override
    public List<BoBookType> selectAllBookTypeByStatus() {
        return boBookTypeMapper.selectAllBookTypeByStatus();
    }

    /**
     * 查询图书类型管理列表
     *
     * @param boBookType 图书类型管理信息
     * @return 图书类型管理集合
     */
    @Override
    public List<BoBookType> selectBoBookTypeList(BoBookType boBookType) {
        return boBookTypeMapper.selectBoBookTypeList(boBookType);
    }

    /**
     * 新增图书类型管理
     *
     * @param boBookType 图书类型管理信息
     * @return 结果
     */
    @Override
    public int insertBoBookType(BoBookType boBookType) {
        return boBookTypeMapper.insertBoBookType(boBookType);
    }

    /**
     * 修改图书类型管理
     *
     * @param boBookType 图书类型管理信息
     * @return 结果
     */
    @Override
    public int updateBoBookType(BoBookType boBookType) {
        return boBookTypeMapper.updateBoBookType(boBookType);
    }

    /**
     * 删除图书类型管理对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBoBookTypeByIds(Long[] ids) {
        return boBookTypeMapper.deleteBoBookTypeByIds(ids);
    }

    /**
     * 校验图书类型名称
     *
     * @param boBookType 图书类型实体
     * @return
     */
    @Override
    public String checkBookTypeNameUnique(BoBookType boBookType) {
        BoBookType info = boBookTypeMapper.checkBookTypeNameUnique(boBookType.getTypeName());
        Long bookTypeId = StringUtils.isNull(boBookType.getId()) ? -1L : boBookType.getId();
        if (StringUtils.isNotNull(info) && info.getId().longValue() != bookTypeId.longValue()) {
            return BOOK_NO_NOT_UNIQUE;
        }
        return BOOK_NO_UNIQUE;
    }

    /**
     * 校验图书类型编码
     *
     * @param boBookType 图书类型实体
     * @return
     */
    @Override
    public String checkBookTypeNoUnique(BoBookType boBookType) {
        BoBookType info = boBookTypeMapper.checkBookTypeNoUnique(boBookType.getTypeNo());
        Long bookTypeId = StringUtils.isNull(boBookType.getId()) ? -1L : boBookType.getId();
        if (StringUtils.isNotNull(info) && info.getId().longValue() != bookTypeId.longValue()) {
            return BOOK_NO_NOT_UNIQUE;
        }
        return BOOK_NO_UNIQUE;
    }

}
